package com.xywy.fwc.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Typeface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xywy.R;
import com.xywy.find.bean.FwcQuestionBean;

public class FwcQuestionAdapter extends BaseAdapter {
    private List<FwcQuestionBean> list;
    private Context context;
	private Typeface font;
    public static final int RESLOVE = 3;
    public static final int UNRESLOVE = 0;
    public static final int OVERDATE = 1;
	public FwcQuestionAdapter(List<FwcQuestionBean> list, Context context) {
		this.list = list;
		this.context = context;
		font = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		FwcQuestionBean bean = list.get(position);
		ViewHolder holder;
		if(convertView == null){
			holder = new ViewHolder();
			convertView = View.inflate(context, R.layout.fwc_question_item, null);
			holder.tv_status = (TextView) convertView.findViewById(R.id.tv_status);
			holder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
		    convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();	
		}
		holder.tv_status.setTypeface(font);
		holder.tv_title.setText(bean.getTitle());
		int status = Integer.parseInt(bean.getStatus());
        if(status == RESLOVE){
        	holder.tv_status.setText("已解决");
        	holder.tv_status.setBackgroundResource(R.drawable.fwc_question_reslove);
        	holder.tv_status.setTextColor(0xffffffff);
		}else if (status == UNRESLOVE) {
			holder.tv_status.setText("待回复");
			holder.tv_status.setBackgroundResource(R.drawable.fwc_question_unre);
        	holder.tv_status.setTextColor(0xffff7e6a);
		}else if (status == OVERDATE) {
			holder.tv_status.setText("已回复");
			holder.tv_status.setBackgroundResource(R.drawable.fwc_question_reslove);
        	holder.tv_status.setTextColor(0xffffffff);
		}
		return convertView;
	}
	
	class ViewHolder{
		public TextView tv_title;
		public TextView tv_status;
	}

}
